package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.SecurityUtils;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.interceptor.annotation.RepeatSubmit;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.Goods;
import com.qinggeng.project.system.domain.GoodsActivity;
import com.qinggeng.project.system.domain.GoodsKeep;
import com.qinggeng.project.system.service.IGoodsActiviyService;
import com.qinggeng.project.system.service.IGoodsKeepService;
import com.qinggeng.project.system.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品库存信息Controller
 *
 * @author qinggeng
 * @date 2020-06-15
 */
@RestController
@RequestMapping("/system/keep")
public class GoodsKeepController extends BaseController {
    @Autowired
    private IGoodsKeepService goodsKeepService;

    @Autowired
    private IGoodsActiviyService goodsActiviyService;

    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询商品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:keep:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsKeep goodsKeep) {
        goodsKeep.setShopId(SecurityUtils.getShopId());
        startPage();
        List<GoodsKeep> list = goodsKeepService.selectGoodsKeepList(goodsKeep);
        return getDataTable(list);
    }

    /**
     * 导出商品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:keep:export')")
    @Log(title = "商品库存信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsKeep goodsKeep) {
        List<GoodsKeep> list = goodsKeepService.selectGoodsKeepList(goodsKeep);
        ExcelUtil<GoodsKeep> util = new ExcelUtil<GoodsKeep>(GoodsKeep.class);
        return util.exportExcel(list, "keep");
    }

    /**
     * 获取商品库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:keep:query')")
    @GetMapping(value = "/{keepId}")
    public AjaxResult getInfo(@PathVariable("keepId") Long keepId) {
        return AjaxResult.success(goodsKeepService.selectGoodsKeepById(keepId));
    }

    /**
     * 新增商品库存信息
     */
    @PreAuthorize("@ss.hasPermi('system:keep:add')")
    @Log(title = "商品库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody GoodsKeep goodsKeep) {
        goodsKeep.setShopId(SecurityUtils.getShopId());
        return toAjax(goodsKeepService.insertGoodsKeep(goodsKeep));
    }

    /**
     * 修改商品库存信息
     */
    @PreAuthorize("@ss.hasPermi('system:keep:edit')")
    @Log(title = "商品库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsKeep goodsKeep) {
        return toAjax(goodsKeepService.updateGoodsKeep(goodsKeep));
    }

    /**
     * 删除商品库存信息
     */
    @PreAuthorize("@ss.hasPermi('system:keep:remove')")
    @Log(title = "商品库存信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{keepIds}")
    public AjaxResult remove(@PathVariable Long[] keepIds) {
        return toAjax(goodsKeepService.deleteGoodsKeepByIds(keepIds));
    }
}
